#ifndef _EXTERNAL_BOARD_INCLUDE_
#define _EXTERNAL_BOARD_INCLUDE_

#include <set>
#include <string>
#include "igslib_iexternal_board.h"
#include "igslib_iserial_manager.h"


namespace igslib 
{
	class CExternalBoard: public IExternalBoard
	{
        protected:
            IProtectUnit* pu;
            std::set<IExternalBoardEvent*> events;
            std::string va; 
            std::string revision;
            std::string version;
			std::string filename;
			char* rawdata;
			int  RawDlen;
        public:
            enum FuseType
            {
                program,
                jtag,
                fuse_count
            };
            CExternalBoard()
			{
                pu = nullptr;
				version="090";
				rawdata = NULL;
				RawDlen=0;				
			}
            virtual IProtectUnit* GetProtectUnit() { return pu; }
            virtual void SetEventHandler(IExternalBoardEvent* value) { events.insert(value); }
            virtual bool GetFuseState(int inx) { return false; }
			virtual std::string GetSourceVersion() { return "N/A" ;}
            virtual std::string GetVersion() { return version; }
            virtual int Upgrade() { return 0; }
            virtual void Update() { }
            virtual void SetSPI(ISpi*) { }
            virtual void SetUART(IUart*) { }
			virtual void SetSourceDst(const std::string& name){filename=name;}
			virtual void ImportRawData(char* data,int len){}
	};

    class CSerialExternalBoard:public CExternalBoard
    {
        protected:
            ISpi* spi;
            IUart* uart;
        public:
            CSerialExternalBoard()
            {
                spi = nullptr;
                uart = nullptr;
            }
            virtual void SetSPI(ISpi* value) { spi = value; }
            virtual void SetUART(IUart* value) { uart = value; }
    };
	
    class CExternalBoardManager:public IExternalBoardManager
    {
        static IExternalBoardManager* instance;
        public:
			static IExternalBoardManager* GetInstance();
            virtual IExternalBoard* New_MH_MCU();
            virtual IExternalBoard* New_ProjMCU(const std::string&);
    };

};

extern "C"{
	 igslib::IExternalBoardManager* GetExternalBoardManagerInstance();
}


#endif
